<?php

/**
 * 
 * @project     : innoTweets 1.0
 * @author      : Dino (DBK)
 * 
 * @package     : User Profile
 * @description : User profile mobile
 * 
 */
if (!defined('BASEPATH')) {
  exit('No direct script access allowed');
}

class Profile extends MOBILE_AUTH_Controller {

  public function index() {

    $user_id = (int) $this->input->get('user_id', TRUE);

    if (!empty($user_id)) {

      // Getting user details
      $get_user_by_id = $this->user_model->get_user_by_id($user_id);

      // Checking user details
      if ($get_user_by_id['status'] == 1 && !empty($get_user_by_id['result'])) {

        // Block accessing resigned user's profile
        if ($get_user_by_id['result']['user_resigned'] != 1) {

          $this->response['status'] = 1;
          $this->response['message'] = 'Success';
          $this->response['data'] = array('user' => $this->make_response($get_user_by_id['result']));
        } else {
          $this->response['message'] = 'User resigned';
        }
      } else {
        $this->response['message'] = 'User not exists';
      }
    } else {
      $this->response['message'] = 'Invalid user id';
    }
  }

  private function make_response($user_data = array()) {
    $user_details['user_id'] = $user_data['user_id'];
    $user_details['user_name'] = $user_data['user_name'];
    $user_details['user_display_name'] = $user_data['user_display_name'];
    $user_details['user_likes_level'] = $user_data['user_likes_level'];
    $user_details['user_gender'] = $user_data['user_gender'];
    $user_details['user_position'] = $user_data['user_position'];
    $user_details['user_skills'] = $user_data['user_skills'];
    $user_details['user_hobbies'] = $user_data['user_hobbies'];
    $user_details['user_place'] = $user_data['user_place'];
    $user_details['user_profile_url'] = site_url('profile/' . $user_data['user_name']);
    $user_details['user_image_url'] = site_url('assets/photos/' . $user_data['user_image']);
    return $user_details;
  }

  public function __destruct() {
    echo json_encode($this->response);
  }

}

?>